package cn.edu.jlu.community.disuse;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;

import java.lang.reflect.Method;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.edu.jlu.community.R;
import cn.edu.jlu.community.disuse.HomePagerAdapter;

public class Home extends FragmentActivity {

    @InjectView(R.id.view_pager)
    ViewPager mViewPager;
    @InjectView(R.id.pager_tabstrip)
    PagerTabStrip mPagerTabStrip;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setupLayout();
    }

    private void setupLayout() {
        setContentView(R.layout.deprecated_main_act);

        ButterKnife.inject(this);

//        mDrawer = MenuDrawer.attach(this, MenuDrawer.Type.OVERLAY);
//        mDrawer.setContentView(R.layout.deprecated_main_act);
//        mDrawer.setMenuView(R.layout.deprecated_drawer_main);
//
//        mDrawer.setSlideDrawable(R.drawable.ic_drawer);
//        mDrawer.setDrawerIndicatorEnabled(true);

        // Set an adapter for ViewPager
        mViewPager.setAdapter(new HomePagerAdapter(getSupportFragmentManager(), this));

        mPagerTabStrip.setDrawFullUnderline(false);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.ac_main, menu);
        return true;
    }

    @Override
    public boolean onMenuOpened(int featureId, Menu menu) {
        // Show menu icons
        if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
            if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
                try {
                    Method m = menu.getClass().getDeclaredMethod(
                            "setOptionalIconsVisible", Boolean.TYPE);
                    m.setAccessible(true);
                    m.invoke(menu, true);
                } catch (Exception e) {
                }
            }
        }
        return super.onMenuOpened(featureId, menu);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
//                mDrawer.toggleMenu();
                return true;
            case R.id.action_settings:
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

}
